/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.googlecode.mailnet.emf.netmodel.impl;

import com.googlecode.mailnet.emf.netmodel.DistributionModel;
import com.googlecode.mailnet.emf.netmodel.LinkModel;
import com.googlecode.mailnet.emf.netmodel.MessageFlowModel;
import com.googlecode.mailnet.emf.netmodel.NetmodelPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Message Flow Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.MessageFlowModelImpl#getMessagesAmountDistribution <em>Messages Amount Distribution</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.MessageFlowModelImpl#getMessageSizeDistribution <em>Message Size Distribution</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.MessageFlowModelImpl#getMessagesPriority <em>Messages Priority</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.MessageFlowModelImpl#getRoute <em>Route</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.MessageFlowModelImpl#getName <em>Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MessageFlowModelImpl extends EObjectImpl implements MessageFlowModel {
	/**
	 * The cached value of the '{@link #getMessagesAmountDistribution() <em>Messages Amount Distribution</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessagesAmountDistribution()
	 * @generated
	 * @ordered
	 */
	protected DistributionModel messagesAmountDistribution;

	/**
	 * The cached value of the '{@link #getMessageSizeDistribution() <em>Message Size Distribution</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessageSizeDistribution()
	 * @generated
	 * @ordered
	 */
	protected DistributionModel messageSizeDistribution;

	/**
	 * The default value of the '{@link #getMessagesPriority() <em>Messages Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessagesPriority()
	 * @generated
	 * @ordered
	 */
	protected static final int MESSAGES_PRIORITY_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMessagesPriority() <em>Messages Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessagesPriority()
	 * @generated
	 * @ordered
	 */
	protected int messagesPriority = MESSAGES_PRIORITY_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRoute() <em>Route</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRoute()
	 * @generated
	 * @ordered
	 */
	protected EList<LinkModel> route;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MessageFlowModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return NetmodelPackage.Literals.MESSAGE_FLOW_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DistributionModel getMessagesAmountDistribution() {
		if (messagesAmountDistribution != null && messagesAmountDistribution.eIsProxy()) {
			InternalEObject oldMessagesAmountDistribution = (InternalEObject)messagesAmountDistribution;
			messagesAmountDistribution = (DistributionModel)eResolveProxy(oldMessagesAmountDistribution);
			if (messagesAmountDistribution != oldMessagesAmountDistribution) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION, oldMessagesAmountDistribution, messagesAmountDistribution));
			}
		}
		return messagesAmountDistribution;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DistributionModel basicGetMessagesAmountDistribution() {
		return messagesAmountDistribution;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMessagesAmountDistribution(DistributionModel newMessagesAmountDistribution) {
		DistributionModel oldMessagesAmountDistribution = messagesAmountDistribution;
		messagesAmountDistribution = newMessagesAmountDistribution;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION, oldMessagesAmountDistribution, messagesAmountDistribution));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DistributionModel getMessageSizeDistribution() {
		if (messageSizeDistribution != null && messageSizeDistribution.eIsProxy()) {
			InternalEObject oldMessageSizeDistribution = (InternalEObject)messageSizeDistribution;
			messageSizeDistribution = (DistributionModel)eResolveProxy(oldMessageSizeDistribution);
			if (messageSizeDistribution != oldMessageSizeDistribution) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION, oldMessageSizeDistribution, messageSizeDistribution));
			}
		}
		return messageSizeDistribution;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DistributionModel basicGetMessageSizeDistribution() {
		return messageSizeDistribution;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMessageSizeDistribution(DistributionModel newMessageSizeDistribution) {
		DistributionModel oldMessageSizeDistribution = messageSizeDistribution;
		messageSizeDistribution = newMessageSizeDistribution;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION, oldMessageSizeDistribution, messageSizeDistribution));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMessagesPriority() {
		return messagesPriority;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMessagesPriority(int newMessagesPriority) {
		int oldMessagesPriority = messagesPriority;
		messagesPriority = newMessagesPriority;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_PRIORITY, oldMessagesPriority, messagesPriority));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LinkModel> getRoute() {
		if (route == null) {
			route = new EObjectResolvingEList<LinkModel>(LinkModel.class, this, NetmodelPackage.MESSAGE_FLOW_MODEL__ROUTE);
		}
		return route;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, NetmodelPackage.MESSAGE_FLOW_MODEL__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION:
				if (resolve) return getMessagesAmountDistribution();
				return basicGetMessagesAmountDistribution();
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION:
				if (resolve) return getMessageSizeDistribution();
				return basicGetMessageSizeDistribution();
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_PRIORITY:
				return new Integer(getMessagesPriority());
			case NetmodelPackage.MESSAGE_FLOW_MODEL__ROUTE:
				return getRoute();
			case NetmodelPackage.MESSAGE_FLOW_MODEL__NAME:
				return getName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION:
				setMessagesAmountDistribution((DistributionModel)newValue);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION:
				setMessageSizeDistribution((DistributionModel)newValue);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_PRIORITY:
				setMessagesPriority(((Integer)newValue).intValue());
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__ROUTE:
				getRoute().clear();
				getRoute().addAll((Collection<? extends LinkModel>)newValue);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__NAME:
				setName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION:
				setMessagesAmountDistribution((DistributionModel)null);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION:
				setMessageSizeDistribution((DistributionModel)null);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_PRIORITY:
				setMessagesPriority(MESSAGES_PRIORITY_EDEFAULT);
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__ROUTE:
				getRoute().clear();
				return;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__NAME:
				setName(NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_AMOUNT_DISTRIBUTION:
				return messagesAmountDistribution != null;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGE_SIZE_DISTRIBUTION:
				return messageSizeDistribution != null;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__MESSAGES_PRIORITY:
				return messagesPriority != MESSAGES_PRIORITY_EDEFAULT;
			case NetmodelPackage.MESSAGE_FLOW_MODEL__ROUTE:
				return route != null && !route.isEmpty();
			case NetmodelPackage.MESSAGE_FLOW_MODEL__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (messagesPriority: ");
		result.append(messagesPriority);
		result.append(", name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //MessageFlowModelImpl
